<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="right">
            <el-upload class="upload-demo" :http-request="importFile">
              <el-button type="primary" icon="el-icon-upload" :disabled="loading">导入附件</el-button>
              <template #tip>
                <div class="el-upload__tip">
                  单文件导入商家以及团队成员,单个文件不要超过10M,请上传.xlsx格式文件
                </div>
              </template>
            </el-upload>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">关 闭</el-button>
		</template>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "import",
				titleMap: {
					add: '导入.xlsx文件',
				},
				visible: false,
				isSaveing: false,
                loading: false,
				parentSearch: {},
				//表单数据
				form: {
					id:"",
					name: "",
					alias: "",
					sort: 1,
					status: 1,
					remark: ""
				},
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add', search = {}){
				this.mode = mode;
                this.parentSearch = search
				this.visible = true;
				return this
			},
            //导入
            async importFile(item) {
                this.loading = true
                let formData = new FormData()
                formData.append('file', item.file)
                var res = await this.$API.develop.district.import.post(formData);
                this.loading = false
                if(res.code == 200) {
                    this.visible = false;
					this.$message.success("文件导入成功")
                } else {
                    this.$alert(res.message, "提示", {type: 'error'})
                }
            },
			//表单注入数据
			setData() {
				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				//Object.assign(this.form, data)
			},
		}
	}
</script>

<style>
</style>
